jackherd 1.3.0 → 1.5.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 +11 -0
- package/README.md +107 -37
- package/dist/{chunk-UI3AZNZF.js → chunk-HQAONP4W.js} +2 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.js +23 -1
- package/dist/plan-format.d.ts +2 -0
- package/dist/plan-format.js +1 -1
- package/herdr-plugin/herdr-plugin.toml +1 -1
- package/install.sh +1 -1
- package/kit/hooks/hooks/ask-hint/decision.ts +28 -0
- package/kit/hooks/hooks/ask-hint/index.ts +44 -0
- package/kit/hooks/hooks/ask-hint/settings.ts +21 -0
- package/kit/hooks/hooks/ask-hint/transcript.ts +55 -0
- package/kit/hooks/hooks/merge-guard/check-free.ts +70 -0
- package/kit/hooks/hooks/merge-guard/decision.ts +2 -1
- package/kit/hooks/hooks/merge-guard/gh.ts +12 -0
- package/kit/hooks/hooks/merge-guard/pull-request.ts +27 -10
- package/kit/hooks/hooks/merge-guard/run.ts +22 -8
- package/kit/hooks/hooks/merge-guard/settings.ts +20 -4
- package/kit/hooks/hooks.json +8 -0
- package/kit/workflow/skills/follow/SKILL.md +10 -3
- package/kit/workflow/skills/orchestrate/SKILL.md +17 -6
- package/package.json +1 -1
- package/schemas/jackherd.schema.json +26 -0
- package/src/config/schema.ts +35 -0
- package/src/plans/lane-standing.ts +59 -0
- package/src/plans/layout.ts +32 -12
- package/src/plans/texts.ts +5 -1
- package/src/sync/render.ts +6 -1
- package/src/vocabulary/index.ts +4 -0
- package/src/watch/command.ts +20 -1
- package/src/watch/heartbeat-progress.ts +47 -0
- package/src/watch/source-command.ts +16 -0
- package/src/watch/source-run.ts +8 -1
- package/src/watch/stream-output.ts +20 -3
|
@@ -4,10 +4,17 @@
|
|
|
4
4
|
* says which branch pull request <number> carries.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
import { runGh } from './gh'
|
|
8
8
|
|
|
9
9
|
type PullRequestView = { headRefName?: unknown; isCrossRepository?: unknown; state?: unknown }
|
|
10
10
|
|
|
11
|
+
/** Where a pull request lives and how many files it changes, as GitHub's `pr view` says. */
|
|
12
|
+
export type RepositoryFacts = { repository: string; changedFiles: number }
|
|
13
|
+
|
|
14
|
+
const VIEW_FIELDS = 'headRefName,isCrossRepository,state,url,changedFiles'
|
|
15
|
+
const PULL_REQUEST_URL = /^https:\/\/github\.com\/([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)\/pull\/[1-9]\d*$/
|
|
16
|
+
|
|
17
|
+
|
|
11
18
|
/** The head branch of an open pull request from this repository; a fork's branch name proves nothing. */
|
|
12
19
|
export const parseHeadBranch = (json: string): string | undefined => {
|
|
13
20
|
try {
|
|
@@ -21,13 +28,23 @@ export const parseHeadBranch = (json: string): string | undefined => {
|
|
|
21
28
|
}
|
|
22
29
|
}
|
|
23
30
|
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The repository from the pull request's own url (host github.com, plain owner and name) and its file count. The
|
|
33
|
+
* file list is then asked of that repository by name, so it cannot come from another one than `gh pr merge` merges in.
|
|
34
|
+
*/
|
|
35
|
+
export const parseRepositoryFacts = (json: string): RepositoryFacts | undefined => {
|
|
36
|
+
try {
|
|
37
|
+
const view: unknown = JSON.parse(json)
|
|
38
|
+
if (typeof view !== 'object' || view === null) return undefined
|
|
39
|
+
const { url, changedFiles } = view as { url?: unknown; changedFiles?: unknown }
|
|
40
|
+
const repository = typeof url === 'string' ? url.match(PULL_REQUEST_URL)?.[1] : undefined
|
|
41
|
+
const counted = typeof changedFiles === 'number' && Number.isInteger(changedFiles) && changedFiles >= 0
|
|
42
|
+
return repository !== undefined && counted ? { repository, changedFiles } : undefined
|
|
43
|
+
} catch {
|
|
44
|
+
return undefined
|
|
45
|
+
}
|
|
33
46
|
}
|
|
47
|
+
|
|
48
|
+
/** Runs `gh pr view <number>` in `directory`, the directory the command itself runs in; any failure answers nothing. */
|
|
49
|
+
export const viewPullRequest = (pullRequest: number, directory: string): string | undefined =>
|
|
50
|
+
runGh(['pr', 'view', String(pullRequest), '--json', VIEW_FIELDS], directory)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs'
|
|
2
2
|
import { isAbsolute, relative } from 'node:path'
|
|
3
3
|
import { approvedBranches, parseTranscript } from './approval'
|
|
4
|
+
import { allFilesMatch, changedFilesOf } from './check-free'
|
|
4
5
|
import { decideBashCommand, type GuardPolicy, type MergeGuardDecision } from './decision'
|
|
5
|
-
import {
|
|
6
|
+
import { parseHeadBranch, parseRepositoryFacts, type RepositoryFacts, viewPullRequest } from './pull-request'
|
|
6
7
|
import { type GuardSettings, readGuardSettings } from './settings'
|
|
7
8
|
|
|
8
9
|
type HookInput = { tool_input?: { command?: unknown }; transcript_path?: unknown; cwd?: unknown }
|
|
@@ -25,13 +26,21 @@ const isInside = (directory: string, project: string): boolean => {
|
|
|
25
26
|
return path === '' || (!path.startsWith('..') && !isAbsolute(path))
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
/** Every file of the pull request, as GitHub lists them, matches `merge.withoutChecks`. */
|
|
30
|
+
const isCheckFree = (
|
|
31
|
+
pullRequest: number,
|
|
32
|
+
facts: RepositoryFacts | undefined,
|
|
33
|
+
withoutChecks: readonly string[],
|
|
34
|
+
directory: string,
|
|
35
|
+
): boolean => facts !== undefined && allFilesMatch(changedFilesOf(pullRequest, directory, facts) ?? [], withoutChecks)
|
|
36
|
+
|
|
28
37
|
const policyFor = (input: HookInput, label: string, projectDirectory: string): GuardPolicy => {
|
|
29
38
|
const settings = readGuardSettings(projectDirectory)
|
|
30
39
|
const directory = typeof input.cwd === 'string' && input.cwd !== '' ? input.cwd : projectDirectory
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
if (!
|
|
34
|
-
return
|
|
40
|
+
const views = new Map<number, string | undefined>()
|
|
41
|
+
const viewOf = (pullRequest: number): string => {
|
|
42
|
+
if (!views.has(pullRequest)) views.set(pullRequest, viewPullRequest(pullRequest, directory))
|
|
43
|
+
return views.get(pullRequest) ?? ''
|
|
35
44
|
}
|
|
36
45
|
let approved: Set<string> | undefined
|
|
37
46
|
return {
|
|
@@ -39,9 +48,14 @@ const policyFor = (input: HookInput, label: string, projectDirectory: string): G
|
|
|
39
48
|
isMergeApproved: (pullRequest) => {
|
|
40
49
|
if (!isInside(directory, projectDirectory)) return false
|
|
41
50
|
const branches = (approved ??= approvedBranchesFrom(input.transcript_path, settings, label))
|
|
42
|
-
if (branches.size === 0) return false
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
if (branches.size === 0 && settings.withoutChecks.length === 0) return false
|
|
52
|
+
// The branch lookup also proves the pull request is open and from this repository; both paths need that.
|
|
53
|
+
const view = viewOf(pullRequest)
|
|
54
|
+
const branch = parseHeadBranch(view)
|
|
55
|
+
if (branch === undefined) return false
|
|
56
|
+
return (
|
|
57
|
+
branches.has(branch) || isCheckFree(pullRequest, parseRepositoryFacts(view), settings.withoutChecks, directory)
|
|
58
|
+
)
|
|
45
59
|
},
|
|
46
60
|
}
|
|
47
61
|
}
|
|
@@ -5,17 +5,30 @@ import { join } from 'node:path'
|
|
|
5
5
|
export type GuardSettings = {
|
|
6
6
|
commands: string[]
|
|
7
7
|
selfMerge: { offer: boolean; approvalMinutes: number }
|
|
8
|
+
/** Path patterns of a pull request that is merged without checks; empty means every merge waits for them. */
|
|
9
|
+
withoutChecks: string[]
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
export const DEFAULT_SETTINGS: GuardSettings = {
|
|
11
13
|
commands: ['gh pr merge', 'gh workflow run'],
|
|
12
14
|
selfMerge: { offer: true, approvalMinutes: 180 },
|
|
15
|
+
withoutChecks: [],
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
const CONFIG_PATH = join('.jackherd', 'config.json')
|
|
16
19
|
export const GUARDED_COMMAND = /^[a-z][a-z0-9-]*( [a-z][a-z0-9-]*){1,3}$/
|
|
17
20
|
export const MAX_MINUTES = 1440
|
|
18
21
|
|
|
22
|
+
/** The same rules as `checkFreePattern` in the config schema, which the hook cannot import. */
|
|
23
|
+
const isCheckFreePattern = (value: unknown): value is string =>
|
|
24
|
+
typeof value === 'string' &&
|
|
25
|
+
/^[A-Za-z0-9_.*/-]+$/.test(value) &&
|
|
26
|
+
!value.startsWith('/') &&
|
|
27
|
+
!value.split('/').includes('..') &&
|
|
28
|
+
value.split('/').some((segment) => /^[A-Za-z0-9][A-Za-z0-9_.-]*$/.test(segment))
|
|
29
|
+
|
|
30
|
+
const isPatternList = (value: unknown): value is string[] => Array.isArray(value) && value.every(isCheckFreePattern)
|
|
31
|
+
|
|
19
32
|
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
20
33
|
typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
21
34
|
|
|
@@ -25,13 +38,13 @@ const isCommandList = (value: unknown): value is string[] =>
|
|
|
25
38
|
const isMinutes = (value: unknown): value is number =>
|
|
26
39
|
typeof value === 'number' && Number.isInteger(value) && value >= 1 && value <= MAX_MINUTES
|
|
27
40
|
|
|
28
|
-
/** The
|
|
29
|
-
const
|
|
41
|
+
/** The first config that exists; the hook has no schema library, `jh` validates the file. */
|
|
42
|
+
const readConfig = (directories: string[]): Record<string, unknown> => {
|
|
30
43
|
const path = directories.map((directory) => join(directory, CONFIG_PATH)).find((candidate) => existsSync(candidate))
|
|
31
44
|
if (!path) return {}
|
|
32
45
|
try {
|
|
33
46
|
const config: unknown = JSON.parse(readFileSync(path, 'utf8'))
|
|
34
|
-
return isRecord(config)
|
|
47
|
+
return isRecord(config) ? config : {}
|
|
35
48
|
} catch {
|
|
36
49
|
return {}
|
|
37
50
|
}
|
|
@@ -42,7 +55,9 @@ const readGuardSection = (directories: string[]): Record<string, unknown> => {
|
|
|
42
55
|
* malformed keeps its default, so a broken config guards more, never less; only an empty list switches the guard off.
|
|
43
56
|
*/
|
|
44
57
|
export const readGuardSettings = (projectDirectory: string, home: string = homedir()): GuardSettings => {
|
|
45
|
-
const
|
|
58
|
+
const config = readConfig([projectDirectory, home])
|
|
59
|
+
const section = isRecord(config.guard) ? config.guard : {}
|
|
60
|
+
const merge = isRecord(config.merge) ? config.merge : {}
|
|
46
61
|
const selfMerge = isRecord(section.selfMerge) ? section.selfMerge : {}
|
|
47
62
|
return {
|
|
48
63
|
commands: isCommandList(section.commands) ? section.commands : DEFAULT_SETTINGS.commands,
|
|
@@ -52,5 +67,6 @@ export const readGuardSettings = (projectDirectory: string, home: string = homed
|
|
|
52
67
|
? selfMerge.approvalMinutes
|
|
53
68
|
: DEFAULT_SETTINGS.selfMerge.approvalMinutes,
|
|
54
69
|
},
|
|
70
|
+
withoutChecks: isPatternList(merge.withoutChecks) ? merge.withoutChecks : DEFAULT_SETTINGS.withoutChecks,
|
|
55
71
|
}
|
|
56
72
|
}
|
package/kit/hooks/hooks.json
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
+
"ask-hint": {
|
|
3
|
+
"event": "Stop",
|
|
4
|
+
"handler": {
|
|
5
|
+
"type": "command",
|
|
6
|
+
"command": "cd \"$CLAUDE_PROJECT_DIR\" && bun .claude/hooks/ask-hint/index.ts",
|
|
7
|
+
"timeout": 10
|
|
8
|
+
}
|
|
9
|
+
},
|
|
2
10
|
"format-on-edit": {
|
|
3
11
|
"event": "PostToolUse",
|
|
4
12
|
"matcher": "Edit|Write",
|
|
@@ -6,7 +6,7 @@ argument-hint: 'What to follow, e.g. a ticket key, an issue or a query'
|
|
|
6
6
|
|
|
7
7
|
If `.claude/project/follow.md` exists, read it first. It extends this skill for this project and wins where the two disagree.
|
|
8
8
|
|
|
9
|
-
You add one entry to `watch.sources`, so that `jh watch` reports a new or changed entry of an external service as `=== source <name> …`. You run only reading commands; the one file you write is the project's `.jackherd/config.json` in the main checkout, and only after the user approved the entry. How sources work, their fields and limits: the
|
|
9
|
+
You add one entry to `watch.sources`, so that `jh watch` reports a new or changed entry of an external service as `=== source <name> …`. You run only reading commands; the one file you write is the project's `.jackherd/config.json` in the main checkout, and only after the user approved the entry. How sources work, their fields and limits: the jackherd README, section **Source reports** and **Recipes**, in the installed package (`"$(dirname "$(readlink -f "$(command -v jh)")")/../README.md"`). Read those two sections; do not copy a recipe from memory.
|
|
10
10
|
|
|
11
11
|
## 1. Ask
|
|
12
12
|
|
|
@@ -20,7 +20,7 @@ One `AskUserQuestion` round in {{kit.responseLanguage}}, only for what the argum
|
|
|
20
20
|
|
|
21
21
|
## 2. Check, read only
|
|
22
22
|
|
|
23
|
-
- The tool: `command -v <tool>` for the recipe's program (`curl`, the service's CLI).
|
|
23
|
+
- The tool: `command -v <tool>` for the recipe's program (`curl`, the service's CLI, and `bun` for a recipe with a script).
|
|
24
24
|
- The login: the tool's own status command where it has one. For a token in an environment variable only whether it is set: `test -n "$<VARIABLE>" && echo set || echo missing`. Never print, echo or pass on a token's value, and never read a file that holds one.
|
|
25
25
|
|
|
26
26
|
Anything missing goes to the user as the command to run themselves (`! <command>`); wait until they did, then check again.
|
|
@@ -29,7 +29,14 @@ Anything missing goes to the user as the command to run themselves (`! <command>
|
|
|
29
29
|
|
|
30
30
|
Before filling, read the help of the installed CLI version for every command the recipe calls (`acli jira workitem search --help` and `workitem view --help`, `gh issue list --help`) and confirm that the fields and options the entry needs exist there. Read the provider's web documentation only when the help leaves it open or no recipe fits. A recipe is a starting point; the installed version decides.
|
|
31
31
|
|
|
32
|
-
Fill the recipe with the item or query and the answers from step 1: a `name` of letters, digits, `.`, `_` and `-` that says what is followed, `lane` and `ignoreAuthors` where chosen. A recipe that needs a script (a token
|
|
32
|
+
Fill the recipe with the item or query and the answers from step 1: a `name` of letters, digits, `.`, `_` and `-` that says what is followed, `lane` and `ignoreAuthors` where chosen. A recipe that needs a script (a token from the environment, or one call per item) gets TypeScript run by Bun: write it to the scratchpad first as `<name>.ts`, never into the repository before step 4, and let the entry's `command` be `["bun", "scripts/sources/<name>.ts"]`. The script:
|
|
33
|
+
|
|
34
|
+
- bounds every request and every call of a tool with `AbortSignal.timeout(20_000)`, where a shell recipe would use `--max-time`;
|
|
35
|
+
- reads a token only from `process.env`, and never prints it, passes it as an argument or writes it into an output;
|
|
36
|
+
- ends with `process.exit(1)` when the token is missing, the answer is not 2xx (or carries an `errors` list, as GraphQL does with a 200) or a tool it calls fails, without printing the answer's body, so a failure is an exit code and never an empty list the watcher would take for a source with nothing new;
|
|
37
|
+
- prints one JSON value on stdout and nothing else.
|
|
38
|
+
|
|
39
|
+
A recipe that needs no script (`gh …`, `curl` on a public page, `curl --netrc`) stays a direct command. Write `bun` as the program, never an absolute path to it: the watcher starts a source without a shell and resolves `bun` to the Bun that runs the watcher, and a path in the config would differ from machine to machine.
|
|
33
40
|
|
|
34
41
|
Write the entry as one JSON object to a draft file in the scratchpad and run, from the main checkout:
|
|
35
42
|
|
|
@@ -122,7 +122,8 @@ stay approval-bound (§ 5, § 6).
|
|
|
122
122
|
`git add <paths>`, `git commit -m "docs(plans): add the <topic> plan"` (English, like every commit
|
|
123
123
|
message), `git push -u origin docs/plan-<topic>`, open the PR per `pull-requests.md`, `cd` back,
|
|
124
124
|
and `git worktree remove {{kit.worktreeDirectory}}/docs-plan-<topic>`. The copies in the main
|
|
125
|
-
checkout stay until the PR is merged (§ 6).
|
|
125
|
+
checkout stay until the PR is merged (§ 6). When this PR is merged by self-merge, it needs no check wait if it qualifies under
|
|
126
|
+
**Merging without checks** (§ 5, **Self-merge**, step 2). Answered no: no lane of these plans starts; say why,
|
|
126
127
|
and do not ask again in this run unless the user raises it.
|
|
127
128
|
1. **Collision check.** Compare the lane's `{{kit.heading.writes}}` set and serial markers with every
|
|
128
129
|
running lane. Shared paths run one after the other; migrations, database pushes and bumps of the
|
|
@@ -287,7 +288,9 @@ has no value, and `--coordinator <name>` names you. Without either the watcher l
|
|
|
287
288
|
|
|
288
289
|
In a stream each report is printed in one piece, so it arrives as one message, and the watcher
|
|
289
290
|
keeps running. The heartbeat there is one line, `=== heartbeat <time> · <lane> <status> · …`, due
|
|
290
|
-
after that many minutes without a report.
|
|
291
|
+
after that many minutes without a report. A lane that is `working` carries its plan progress after a colon (`<lane> working: P12 7/12`, the current phase and its ticks)
|
|
292
|
+
only when the count moved since the last heartbeat. Pass it on as it is. A working lane without a number
|
|
293
|
+
has not moved (or has no plan): read its screen yourself when that lasts. `lane added: <name>` and `lane removed: <name>` mark a
|
|
291
294
|
change of the found lanes. A lane's agent is watched from the state it shows when it first appears,
|
|
292
295
|
so an agent that starts out idle does not fire; a lane whose agent exits fires as `no longer listed`,
|
|
293
296
|
also when it leaves the found lanes with it.
|
|
@@ -518,16 +521,24 @@ When the user picked `"{{kit.guard.selfMergeLabel}}"` for a PR:
|
|
|
518
521
|
1. Commit, push and open the PR as in step 4. Enter in the board's `{{kit.heading.history}}` that the
|
|
519
522
|
user approved this PR with self-merge (time, lane, PR number), so the approval has a record outside
|
|
520
523
|
the chat.
|
|
521
|
-
2.
|
|
524
|
+
2. **Merging without checks.** The paths a PR may carry to be merged without waiting for checks are
|
|
525
|
+
`{{kit.merge.withoutChecks}}` (`merge.withoutChecks` in the config; `none` means every merge waits).
|
|
526
|
+
Unless `none`, list the PR's files with `gh pr diff <n> --name-only` and compare each one with the
|
|
527
|
+
patterns yourself. When **every** file matches, go straight to step 4: no checks wait, because
|
|
528
|
+
the config says these paths need none. One file outside, an empty list, or a failed `gh` call:
|
|
529
|
+
go on with step 3. The merge guard reads the file list from GitHub itself and lets that
|
|
530
|
+
merge pass without a question only when it agrees; if it asks, the dialog is the user's (step 5).
|
|
531
|
+
This is the rule for the documents of a plan commit as well (§ 2 step 0).
|
|
532
|
+
3. Wait for the checks in the background, never in the foreground (§ 4): a Bash call
|
|
522
533
|
`gh pr checks <n> --watch` with `run_in_background: true`, then work on until it reports.
|
|
523
|
-
|
|
534
|
+
4. Green (or a PR that qualified in step 2): `gh pr merge <n> --squash --delete-branch`, with the plain PR number and without `-R`,
|
|
524
535
|
`--repo` or `--admin`. The merge guard lets exactly this command through for the approved branch,
|
|
525
536
|
for `guard.selfMerge.approvalMinutes` after the answer. Red, or checks that never finish: do not
|
|
526
537
|
merge, report to the user with the failing check and the lane's next step.
|
|
527
|
-
|
|
538
|
+
5. When the guard asks anyway (the approval lapsed, the branch differs, the command carries an
|
|
528
539
|
option it does not cover), the dialog is the user's. Do not confirm it for them and do not look
|
|
529
540
|
for a way around it: tell them what the PR waits for.
|
|
530
|
-
|
|
541
|
+
6. After the merge, one line to the user (PR, merge commit, checks or "no checks: all files match merge.withoutChecks"), then § 6 as for any merge.
|
|
531
542
|
|
|
532
543
|
Self-merge never covers `gh workflow run` (a release, a deploy) or another PR: each of those asks
|
|
533
544
|
the user every time.
|
package/package.json
CHANGED
|
@@ -486,6 +486,32 @@
|
|
|
486
486
|
},
|
|
487
487
|
"additionalProperties": false
|
|
488
488
|
},
|
|
489
|
+
"merge": {
|
|
490
|
+
"default": {},
|
|
491
|
+
"type": "object",
|
|
492
|
+
"properties": {
|
|
493
|
+
"withoutChecks": {
|
|
494
|
+
"default": [],
|
|
495
|
+
"type": "array",
|
|
496
|
+
"items": {
|
|
497
|
+
"type": "string",
|
|
498
|
+
"pattern": "^[A-Za-z0-9_.*/-]+$"
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
},
|
|
502
|
+
"additionalProperties": false
|
|
503
|
+
},
|
|
504
|
+
"hints": {
|
|
505
|
+
"default": {},
|
|
506
|
+
"type": "object",
|
|
507
|
+
"properties": {
|
|
508
|
+
"askUserQuestion": {
|
|
509
|
+
"default": true,
|
|
510
|
+
"type": "boolean"
|
|
511
|
+
}
|
|
512
|
+
},
|
|
513
|
+
"additionalProperties": false
|
|
514
|
+
},
|
|
489
515
|
"check": {
|
|
490
516
|
"type": "object",
|
|
491
517
|
"properties": {
|
package/src/config/schema.ts
CHANGED
|
@@ -192,6 +192,32 @@ const guardedCommand = z
|
|
|
192
192
|
.string()
|
|
193
193
|
.regex(/^[a-z][a-z0-9-]*( [a-z][a-z0-9-]*){1,3}$/, 'a program and one to three plain words, such as gh pr merge')
|
|
194
194
|
|
|
195
|
+
/**
|
|
196
|
+
* A path pattern for a pull request that needs no checks: plain path words with wildcards, at least one whole path
|
|
197
|
+
* segment without a wildcard that starts with a letter or digit (a docs folder, then wildcards, then a file ending, but
|
|
198
|
+
* not wildcards alone nor any pattern whose only literal is a dot), no `..`, not absolute. Braces, classes and
|
|
199
|
+
* negation stay out, so the hook, which has no schema library, reads exactly what this accepts.
|
|
200
|
+
*/
|
|
201
|
+
const checkFreePattern = z
|
|
202
|
+
.string()
|
|
203
|
+
.regex(/^[A-Za-z0-9_.*/-]+$/, 'path words with * and ** only, such as docs/**/*.md')
|
|
204
|
+
.refine(
|
|
205
|
+
(pattern) => !pattern.startsWith('/') && !pattern.split('/').includes('..'),
|
|
206
|
+
'a relative path that stays inside the repository',
|
|
207
|
+
)
|
|
208
|
+
.refine(
|
|
209
|
+
(pattern) => pattern.split('/').some((segment) => /^[A-Za-z0-9][A-Za-z0-9_.-]*$/.test(segment)),
|
|
210
|
+
'a pattern with a whole path segment that is no wildcard, such as docs/**/*.md',
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
const mergeSchema = z.strictObject({
|
|
214
|
+
/**
|
|
215
|
+
* Paths of pull requests that are merged without waiting for checks: when every file of the pull request matches one
|
|
216
|
+
* of them, `/orchestrate` merges at once and the merge guard does not ask. Empty means every merge waits for checks.
|
|
217
|
+
*/
|
|
218
|
+
withoutChecks: z.array(checkFreePattern).default([]),
|
|
219
|
+
})
|
|
220
|
+
|
|
195
221
|
const guardSchema = z.strictObject({
|
|
196
222
|
/**
|
|
197
223
|
* The commands the merge guard hook asks the user about before they run, also behind options before the verb, a chain,
|
|
@@ -208,6 +234,11 @@ const guardSchema = z.strictObject({
|
|
|
208
234
|
.prefault({}),
|
|
209
235
|
})
|
|
210
236
|
|
|
237
|
+
const hintsSchema = z.strictObject({
|
|
238
|
+
/** Whether the `ask-hint` hook points out a last message that ends in a question while the turn used no `AskUserQuestion`; a lane session is never hinted. */
|
|
239
|
+
askUserQuestion: z.boolean().default(true),
|
|
240
|
+
})
|
|
241
|
+
|
|
211
242
|
const contextSchema = z
|
|
212
243
|
.strictObject({
|
|
213
244
|
/** Share of the context window from which a lane's fill shows yellow and `/implement` offers a new chat. */
|
|
@@ -302,6 +333,10 @@ export const jackherdConfigSchema = z.strictObject({
|
|
|
302
333
|
.prefault({}),
|
|
303
334
|
/** Read by the merge guard hook, which asks before the listed commands run, and by `/orchestrate`. */
|
|
304
335
|
guard: guardSchema.prefault({}),
|
|
336
|
+
/** Read by `/orchestrate` and by the merge guard hook. */
|
|
337
|
+
merge: mergeSchema.prefault({}),
|
|
338
|
+
/** Read by the `ask-hint` hook. */
|
|
339
|
+
hints: hintsSchema.prefault({}),
|
|
305
340
|
/** Read by `jh check`; validated here too, so a typo fails every command alike. */
|
|
306
341
|
check: checkConfigSchema.optional(),
|
|
307
342
|
})
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { LaneProgress, SprintLane } from '../plan-format'
|
|
2
|
+
import { PLAN_VOCABULARY } from '../vocabulary'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `active` lanes are drawn in full; `noAgent` is a worktree nobody works in, still listed; `waiting` has no
|
|
6
|
+
* worktree and still something to do; `closed` has nothing left and is not drawn.
|
|
7
|
+
*/
|
|
8
|
+
export const LANE_STANDING = { active: 'active', noAgent: 'no-agent', waiting: 'waiting', closed: 'closed' } as const
|
|
9
|
+
export type LaneStanding = (typeof LANE_STANDING)[keyof typeof LANE_STANDING]
|
|
10
|
+
|
|
11
|
+
type StandingInput = {
|
|
12
|
+
progress: Pick<LaneProgress, 'lane' | 'done' | 'total'>
|
|
13
|
+
status: { agent: string | null; branch: string | null }
|
|
14
|
+
pullRequests: readonly unknown[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const NO_STARTS_AFTER = new Set(['', '-', '–', '—'])
|
|
18
|
+
|
|
19
|
+
/** The starts-after cell of the lane's newest row that has one, trimmed. */
|
|
20
|
+
const startsAfterOf = ({ steps }: SprintLane): string =>
|
|
21
|
+
steps
|
|
22
|
+
.map((step) => step.startsAfter.trim())
|
|
23
|
+
.reverse()
|
|
24
|
+
.find((cell) => !NO_STARTS_AFTER.has(cell)) ?? ''
|
|
25
|
+
|
|
26
|
+
const STARTS_NOW = Object.values(PLAN_VOCABULARY).flatMap(({ startsNow }) => startsNow)
|
|
27
|
+
|
|
28
|
+
/** Every language's word counts: the language a view answers in is not the language the board is written in. */
|
|
29
|
+
const startsNow = (cell: string): boolean => {
|
|
30
|
+
const lowered = cell.toLowerCase()
|
|
31
|
+
return STARTS_NOW.some(
|
|
32
|
+
(word) => lowered === word || (lowered.startsWith(word) && /^\W/.test(lowered.slice(word.length))),
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** What a waiting lane waits for: its starts-after text as the board writes it; null when it may start at once. */
|
|
37
|
+
export const waitingNote = (lane: SprintLane): string | null => {
|
|
38
|
+
const cell = startsAfterOf(lane)
|
|
39
|
+
return cell === '' || startsNow(cell) ? null : cell
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const hasOpenWork = (progress: StandingInput['progress']): boolean => {
|
|
43
|
+
if (progress.total > 0) return progress.done < progress.total
|
|
44
|
+
return waitingNote(progress.lane) !== null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Where a lane stands on the board. The cleaned-up mark goes first: it closes a lane, unless an agent, a worktree
|
|
49
|
+
* or a pull request is still there, which keeps it listed. Then an agent or an open pull request makes a lane
|
|
50
|
+
* active and a worktree alone lists it. Without a worktree a lane waits while it has open work, else it is closed.
|
|
51
|
+
*/
|
|
52
|
+
export const laneStanding = (input: StandingInput): LaneStanding => {
|
|
53
|
+
const { progress, status, pullRequests } = input
|
|
54
|
+
const working = status.agent !== null || pullRequests.length > 0
|
|
55
|
+
if (progress.lane.closed) return working || status.branch !== null ? LANE_STANDING.noAgent : LANE_STANDING.closed
|
|
56
|
+
if (working) return LANE_STANDING.active
|
|
57
|
+
if (status.branch !== null) return LANE_STANDING.noAgent
|
|
58
|
+
return hasOpenWork(progress) ? LANE_STANDING.waiting : LANE_STANDING.closed
|
|
59
|
+
}
|
package/src/plans/layout.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
type WatchBadges,
|
|
29
29
|
type WatchHealth,
|
|
30
30
|
} from '../watch/plan-badges'
|
|
31
|
+
import { LANE_STANDING, type LaneStanding, laneStanding, waitingNote } from './lane-standing'
|
|
31
32
|
import { chipKey, type LinkChip } from './link-chips'
|
|
32
33
|
import { type PlannedPlan, phaseList, plannedPhaseCount } from './planned'
|
|
33
34
|
import { CHECKS, type ChecksState, type PullRequest, pullRequestKey } from './pull-requests'
|
|
@@ -753,18 +754,27 @@ const laneBlock = (
|
|
|
753
754
|
return joinFrames([row, ...view.pullRequests.map((pullRequest) => pullRequestFrame(pullRequest, context)), content])
|
|
754
755
|
}
|
|
755
756
|
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
progress.lane.closed || (status.agent === null && pullRequests.length === 0)
|
|
757
|
+
const laneTally = ({ progress }: Pick<LaneView, 'progress'>): string =>
|
|
758
|
+
progress.total > 0 ? `${progress.lane.name} ${progress.done}/${progress.total}` : progress.lane.name
|
|
759
759
|
|
|
760
|
-
const parkedItem = (
|
|
761
|
-
const
|
|
762
|
-
const
|
|
763
|
-
const label =
|
|
764
|
-
progress.total > 0 ? `${name} ${progress.done}/${progress.total}` : hasPlan ? name : `${name} (${TEXTS.noPlan})`
|
|
760
|
+
const parkedItem = (view: Pick<LaneView, 'progress'>): string => {
|
|
761
|
+
const hasPlan = view.progress.lane.steps.some((step) => step.planHref)
|
|
762
|
+
const label = view.progress.total > 0 || hasPlan ? laneTally(view) : `${laneTally(view)} (${TEXTS.noPlan})`
|
|
765
763
|
return label.replaceAll(' ', NON_BREAKING_SPACE)
|
|
766
764
|
}
|
|
767
765
|
|
|
766
|
+
/** ` name 2/5 after P1 gemergt`: one dimmed row per lane that waits, its wait cut at the pane's edge. */
|
|
767
|
+
const waitingBlock = (lanes: LaneView[], width: number): string[] => {
|
|
768
|
+
if (lanes.length === 0) return []
|
|
769
|
+
const head = paint.dim(`${NO_AGENT_SYMBOL} ${TEXTS.waiting(lanes.length)}`)
|
|
770
|
+
const rows = lanes.map((lane) => {
|
|
771
|
+
const note = waitingNote(lane.progress.lane)
|
|
772
|
+
const item = laneTally(lane)
|
|
773
|
+
return paint.dim(fit(note === null ? ` ${item}` : ` ${item} ${TEXTS.startsAfter(plain(note))}`, width))
|
|
774
|
+
})
|
|
775
|
+
return [head, ...rows]
|
|
776
|
+
}
|
|
777
|
+
|
|
768
778
|
/** `· no agent (6) name 3/9 · other 1/4`: one wrapping block for every parked lane, each with its progress. */
|
|
769
779
|
const parkedBlock = (lanes: LaneView[], width: number): string[] => {
|
|
770
780
|
if (lanes.length === 0) return []
|
|
@@ -837,19 +847,29 @@ const laneColumnsOf = (lanes: LaneView[]): LaneColumns => ({
|
|
|
837
847
|
right: Math.max(0, ...lanes.map((lane) => visibleLength(laneRight(lane)))),
|
|
838
848
|
})
|
|
839
849
|
|
|
850
|
+
/** The lanes by what the view does with them; closed lanes are in none of the three groups. */
|
|
851
|
+
const partitionLanes = (lanes: LaneView[]): Record<'active' | 'waiting' | 'noAgent', LaneView[]> => {
|
|
852
|
+
const standing = (wanted: LaneStanding) => lanes.filter((lane) => laneStanding(lane) === wanted)
|
|
853
|
+
return {
|
|
854
|
+
active: standing(LANE_STANDING.active),
|
|
855
|
+
waiting: standing(LANE_STANDING.waiting),
|
|
856
|
+
noAgent: standing(LANE_STANDING.noAgent),
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
840
860
|
/**
|
|
841
861
|
* Title and clock on top, the key hint at the bottom (with the legend after `?`), and in between one
|
|
842
862
|
* block per lane: the lane line with its total bar, and for an open lane the phase rows. Folded lanes are
|
|
843
|
-
* one line each
|
|
844
|
-
* agent share
|
|
863
|
+
* one line each and every lane block after the first is preceded by a dimmed rule. Lanes that wait and
|
|
864
|
+
* lanes with a worktree but no agent each share a closing block; finished lanes are not drawn.
|
|
845
865
|
*/
|
|
846
866
|
export const renderScreen = (
|
|
847
867
|
{ title, time, lanes, planned, watch, language = PLAN_LANGUAGE.en }: OverviewView,
|
|
848
868
|
state: Selection,
|
|
849
869
|
width: number,
|
|
850
870
|
): Screen => {
|
|
851
|
-
const active
|
|
852
|
-
const parked =
|
|
871
|
+
const { active, waiting, noAgent } = partitionLanes(lanes)
|
|
872
|
+
const parked = [...waitingBlock(waiting, width), ...parkedBlock(noAgent, width)]
|
|
853
873
|
const columns = laneColumnsOf(active)
|
|
854
874
|
const badgeTexts = BADGE_TEXTS[language]
|
|
855
875
|
const blocks = active.map((lane) => laneBlock(lane, state, width, columns, badgeTexts))
|
package/src/plans/texts.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { NO_AGENT_WORD, PHASE_COUNT } from './symbols'
|
|
|
8
8
|
*/
|
|
9
9
|
export type PlanTexts = {
|
|
10
10
|
noAgent: string
|
|
11
|
+
waiting: (lanes: number) => string
|
|
12
|
+
startsAfter: (wait: string) => string
|
|
11
13
|
noPlan: string
|
|
12
14
|
noWorktree: string
|
|
13
15
|
noRow: string
|
|
@@ -70,6 +72,8 @@ export const boardTexts = (term: string) => ({
|
|
|
70
72
|
|
|
71
73
|
export const TEXTS: PlanTexts = {
|
|
72
74
|
noAgent: NO_AGENT_WORD,
|
|
75
|
+
waiting: (lanes) => `waiting (${lanes})`,
|
|
76
|
+
startsAfter: (wait) => `after ${wait}`,
|
|
73
77
|
noPlan: 'no plan',
|
|
74
78
|
noWorktree: 'no worktree',
|
|
75
79
|
noRow: 'no row in lanes',
|
|
@@ -94,7 +98,7 @@ export const TEXTS: PlanTexts = {
|
|
|
94
98
|
hint: '↑↓ select →← open a all n notes s html q quit ? help',
|
|
95
99
|
legend: [
|
|
96
100
|
'enter/space or click toggles a lane or a phase, click or enter on a task opens its whole text, and opens a ↗ pull request · wheel PgUp PgDn scroll · j k h l like the arrows · click or ctrl+click on a 📎 chip opens its link · ✦ artifact · ⑂ pull request or issue · ◈ Figma · private = the plan says so',
|
|
97
|
-
'⚡ working · ❓ blocked, waits for you · 📨 done = the agent finished its answer, not the lane · ⏸ idle · · no agent · working and blocked lanes open by themselves, → ← overrule until the status changes',
|
|
101
|
+
'⚡ working · ❓ blocked, waits for you · 📨 done = the agent finished its answer, not the lane · ⏸ idle · · no agent = a worktree nobody works in · waiting = not started: no worktree yet, something left to do, and what it starts after; finished lanes (cleaned up, or every named phase ticked) are not shown · working and blocked lanes open by themselves, → ← overrule until the status changes',
|
|
98
102
|
`n/m = m checkboxes of the phase, n ticked (the phase being worked on is yellow; ticked, not merged = all ticked in the worktree, not on the base branch yet) · ${PHASE_COUNT.allTicked} n/n all ticked · ${PHASE_COUNT.empty} no checkboxes · ${PHASE_COUNT.missing} not in the plan · n shows or hides the notes of a lane · s opens every lane and plan as one HTML page · ⎇ branch · ↑ commits ahead · ± uncommitted · no worktree: plan read from main`,
|
|
99
103
|
],
|
|
100
104
|
}
|
package/src/sync/render.ts
CHANGED
|
@@ -12,6 +12,10 @@ const laneCopyCommand = (copy: readonly string[]): string =>
|
|
|
12
12
|
? WORKTREE_INCLUDE_COPY
|
|
13
13
|
: `cd <main-checkout> && cp -p --parents -- ${copy.map((path) => `'${path}'`).join(' ')} <worktree>/`
|
|
14
14
|
|
|
15
|
+
/** The patterns a pull request may match to be merged without checks, as prose for a skill; `none` for an empty list. */
|
|
16
|
+
const checkFreeList = (patterns: readonly string[]): string =>
|
|
17
|
+
patterns.length === 0 ? 'none' : patterns.map((pattern) => `\`${pattern}\``).join(', ')
|
|
18
|
+
|
|
15
19
|
const prefixed = (prefix: string, values: Record<string, string>): [string, string][] =>
|
|
16
20
|
Object.entries(values).map(([key, value]) => [`kit.${prefix}.${key}`, value])
|
|
17
21
|
|
|
@@ -31,6 +35,7 @@ const placeholderValues = (config: JackherdConfig): Map<string, string> => {
|
|
|
31
35
|
...prefixed('board', config.board),
|
|
32
36
|
['kit.guard.selfMergeLabel', SELF_MERGE_LABEL[config.responseLanguage]],
|
|
33
37
|
['kit.guard.selfMerge', config.guard.selfMerge.offer ? 'offered' : 'not offered'],
|
|
38
|
+
['kit.merge.withoutChecks', checkFreeList(config.merge.withoutChecks)],
|
|
34
39
|
...prefixed('heading', { ...header, ...sections, ...columns, phase }),
|
|
35
40
|
])
|
|
36
41
|
}
|
|
@@ -42,7 +47,7 @@ export const listPlaceholders = (template: string): string[] =>
|
|
|
42
47
|
/**
|
|
43
48
|
* Fills the kit placeholders from the project config: `{{kit.model.<role>}}`,
|
|
44
49
|
* `{{kit.command.<test|typecheck|lint|format|install|dev>}}`, `{{kit.lanes.<copyCommand|lockFile>}}`,
|
|
45
|
-
* `{{kit.board.<pattern|file|term>}}`, `{{kit.guard.<selfMerge|selfMergeLabel>}}`, `{{kit.heading.<key>}}` from the plan
|
|
50
|
+
* `{{kit.board.<pattern|file|term>}}`, `{{kit.guard.<selfMerge|selfMergeLabel>}}`, `{{kit.merge.withoutChecks}}`, `{{kit.heading.<key>}}` from the plan
|
|
46
51
|
* vocabulary, the two languages, the plan and worktree directory and the base branch. Other
|
|
47
52
|
* `{{…}}` text is left alone; an unknown `kit.` placeholder throws rather than reaching a project
|
|
48
53
|
* file unrendered. `overrides` win over the config: a global kit renders what each repository decides as
|
package/src/vocabulary/index.ts
CHANGED
|
@@ -59,6 +59,8 @@ export type PlanVocabulary = {
|
|
|
59
59
|
noReviewGate: string
|
|
60
60
|
/** Marks a lane as closed when its name cell contains it. */
|
|
61
61
|
laneClosed: string
|
|
62
|
+
/** Words a starts-after cell begins with when the lane may start at once. */
|
|
63
|
+
startsNow: readonly string[]
|
|
62
64
|
/** Words that may stand between two phases of one entry (`P1 Rule und P2 Monitor`). */
|
|
63
65
|
phaseConnectors: readonly string[]
|
|
64
66
|
statusWords: Record<PlanStatus, StatusWord>
|
|
@@ -82,6 +84,7 @@ export const PLAN_VOCABULARY: Record<PlanLanguage, PlanVocabulary> = {
|
|
|
82
84
|
phase: 'Phase',
|
|
83
85
|
noReviewGate: 'Kein Review-Gate',
|
|
84
86
|
laneClosed: 'abgeräumt',
|
|
87
|
+
startsNow: ['sofort'],
|
|
85
88
|
phaseConnectors: ['danach', 'und', 'dann', 'sowie'],
|
|
86
89
|
statusWords: {
|
|
87
90
|
done: { label: 'Done', leading: ['done'], anywhere: ['abgeschlossen'] },
|
|
@@ -109,6 +112,7 @@ export const PLAN_VOCABULARY: Record<PlanLanguage, PlanVocabulary> = {
|
|
|
109
112
|
phase: 'Phase',
|
|
110
113
|
noReviewGate: 'No review gate',
|
|
111
114
|
laneClosed: 'cleaned up',
|
|
115
|
+
startsNow: ['now', 'immediately'],
|
|
112
116
|
phaseConnectors: ['then', 'and', 'after'],
|
|
113
117
|
statusWords: {
|
|
114
118
|
done: { label: 'Done', leading: ['done'], anywhere: ['completed'] },
|