@able-autonomy/able 0.0.4 → 0.0.7

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/config.ts CHANGED
@@ -33,11 +33,12 @@ export interface WorkspacesConfig {
33
33
  }
34
34
 
35
35
  export interface AbleConfig {
36
- /** `commit`: per folder from the root (`.` for the root itself), run in order for the folders a commit or a landing
37
- * touches; any failure stops it. Kept fast: release checks (builds, tests) come with the Release module (97). */
38
- checks?: { commit?: Record<string, Command[]> }
36
+ /** `commit`: per folder from the root (`.` for the root itself), run in order for the folders a commit or a merge
37
+ * touches; kept fast. `merge`: run from the root after those, at `able ws merge` only (the cross-package checks).
38
+ * Any failure stops it. Release checks (builds, tests) come with the Release module (98). */
39
+ checks?: { commit?: Record<string, Command[]>; merge?: Command[] }
39
40
  workspaces?: WorkspacesConfig
40
- /** The branch workspaces are cut from and land on. */
41
+ /** The branch workspaces are cut from and merged into. */
41
42
  trunk: string
42
43
  /** The journal's folder from the root: `workspaces/<slug>.md` briefs and `weeks/<yyyy>-w<ww>.md` records. */
43
44
  journal: string
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@able-autonomy/able",
3
- "version": "0.0.4",
3
+ "version": "0.0.7",
4
4
  "description": "Able's command line and the config types a host's able.config.ts uses",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/checks.ts CHANGED
@@ -8,7 +8,7 @@ import { bold } from './ui.ts'
8
8
  export const folderOf = (path: string, folders: string[]) =>
9
9
  folders.filter((f) => f !== '.' && (path === f || path.startsWith(`${f}/`))).sort((a, b) => b.length - a.length)[0] ?? (folders.includes('.') ? '.' : undefined)
10
10
 
11
- /** Runs the checks of every folder the paths touch; false at the first failure. */
11
+ /** Runs the commit checks of every folder the paths touch; false at the first failure. */
12
12
  export function runChecks(config: AbleConfig, paths: string[], at: Place): boolean {
13
13
  const checks = config.checks?.commit ?? {}
14
14
  const folders = [...new Set(paths.map((p) => folderOf(p, Object.keys(checks))).filter((f): f is string => Boolean(f)))].sort()
@@ -18,3 +18,10 @@ export function runChecks(config: AbleConfig, paths: string[], at: Place): boole
18
18
  }
19
19
  return true
20
20
  }
21
+
22
+ /** Runs the merge checks from the root; false at the first failure. */
23
+ export function runMergeChecks(config: AbleConfig, at: Place): boolean {
24
+ const checks = config.checks?.merge ?? []
25
+ if (checks.length) console.log(`\n ${bold('merge')}`)
26
+ return checks.every((c) => runCommand(c, at))
27
+ }
package/src/push.ts CHANGED
@@ -1,11 +1,11 @@
1
- // able push: pushes the branch the checkout is on, with its tags. A workspace lands with `able ws merge` instead.
1
+ // able push: pushes the branch the checkout is on, with its tags. A workspace is merged with `able ws merge` instead.
2
2
 
3
3
  import { gitLoud } from './git.ts'
4
4
  import { fail, green } from './ui.ts'
5
5
  import { current } from './workspaces/state.ts'
6
6
 
7
7
  const at = await current()
8
- if (at.isWorkspace) fail('a workspace lands with: able ws merge')
8
+ if (at.isWorkspace) fail('a workspace is merged with: able ws merge')
9
9
  if (!at.branch || at.branch === 'HEAD') fail('not on a branch')
10
10
  if (!gitLoud(at.path, 'push', '--follow-tags', 'origin', at.branch)) fail(`push of ${at.branch} failed`)
11
11
  console.log(`\n ${green('✓')} pushed ${at.branch}\n`)
@@ -4,7 +4,7 @@
4
4
  // able ws ls [--json] every checkout: offset, services, tree, resources held
5
5
  // able ws current [--json] the checkout this runs in: slug, branch, path, port offset, main checkout
6
6
  // able ws refresh merges the trunk into this workspace
7
- // able ws merge ["message"] [--yes] lands this workspace on the trunk as `Land feat/<slug>`
7
+ // able ws merge ["message"] [--yes] merges this workspace into the trunk as `Merge feat/<slug>`
8
8
  // able ws rm <slug> [--force] stops and removes a workspace, deleting its branch once merged
9
9
  // able ws start | stop [<service>…] the workspace's services, in dependency order
10
10
  // able ws status the services running in this checkout
@@ -1,14 +1,16 @@
1
- // able ws merge ["message"] [--yes]: lands this workspace on the trunk, from inside it.
1
+ // able ws merge ["message"] [--yes]: merges this workspace into the trunk, from inside it.
2
2
  //
3
- // Merges origin's trunk into `feat/<slug>`, runs the checks of every folder the branch changed (decision 73), then
4
- // pushes `feat/<slug>` and lands it on origin's trunk as one merge commit, `Land feat/<slug>`, which is how `able sync`
5
- // finds it. A message commits what is still dirty first. The main checkout takes no part; afterwards it is
3
+ // Refuses while the workspace's brief has no `## Ledger` (its close). Merges origin's trunk into `feat/<slug>`, runs the commit checks of every folder the branch changed and then the
4
+ // merge checks (decisions 73, 100), pushes `feat/<slug>` and merges it into origin's trunk as one merge commit,
5
+ // `Merge feat/<slug>`, which is how `able sync` finds it. A message commits what is still dirty first. The main checkout takes no part; afterwards it is
6
6
  // fast-forwarded when it is on the trunk and nothing of its own is in the way.
7
7
  //
8
8
  // A conflict stops it with the files named: resolve them here, commit, and run it again. A push refused because the
9
9
  // trunk moved meanwhile is the same: run it again, and it merges the newer trunk in.
10
10
 
11
- import { runChecks } from '../checks.ts'
11
+ import { existsSync, readFileSync } from 'node:fs'
12
+ import { join, relative } from 'node:path'
13
+ import { runChecks, runMergeChecks } from '../checks.ts'
12
14
  import { count, dirtyCount, fetchTrunk, git, gitLoud, gitQuiet, lines, mergeOrFail } from '../git.ts'
13
15
  import { bold, confirm, dim, fail, green, yellow } from '../ui.ts'
14
16
  import { inWorkspace } from './state.ts'
@@ -21,14 +23,18 @@ const { trunk } = config
21
23
  const dirty = dirtyCount(ws.path)
22
24
  if (dirty && !msg) fail(`${dirty} uncommitted file(s); commit them (able commit), or pass a message to commit them all at once`)
23
25
 
26
+ // The close goes in with the branch: a brief without its ledger is never merged (`able sync` reads that ledger).
27
+ const brief = join(ws.path, config.journal, 'workspaces', `${ws.slug}.md`)
28
+ if (existsSync(brief) && !readFileSync(brief, 'utf8').includes('\n## Ledger\n')) fail(`${relative(ws.path, brief)} has no ## Ledger; close the workspace first (the able-close-ws skill), then merge`)
29
+
24
30
  fetchTrunk(ws.path, trunk)
25
31
  const ahead = count(ws.path, `origin/${trunk}..HEAD`)
26
32
  const behind = count(ws.path, `HEAD..origin/${trunk}`)
27
33
 
28
- console.log(`\n ${bold(`Land ${ws.branch} on ${trunk}`)}`)
29
- console.log(` ${ahead} commit(s) to land${dirty ? `, +${dirty} uncommitted → "${msg}"` : ''}; ${trunk} is ${behind} commit(s) ahead${behind ? ', merged in first' : ''}`)
34
+ console.log(`\n ${bold(`Merge ${ws.branch} into ${trunk}`)}`)
35
+ console.log(` ${ahead} commit(s) to merge${dirty ? `, +${dirty} uncommitted → "${msg}"` : ''}; ${trunk} is ${behind} commit(s) ahead${behind ? ', merged in first' : ''}`)
30
36
  if (!ahead && !dirty) {
31
- console.log(dim(' nothing to land\n'))
37
+ console.log(dim(' nothing to merge\n'))
32
38
  process.exit(0)
33
39
  }
34
40
  if (!args.includes('--yes') && !confirm(`Merge ${trunk} in, run the checks, and push to ${trunk}?`)) fail('aborted; nothing pushed')
@@ -37,24 +43,25 @@ const commitAll = (message: string) => gitLoud(ws.path, 'add', '-A') && gitLoud(
37
43
  if (dirty && msg && !commitAll(msg)) fail('commit failed')
38
44
  if (behind) mergeOrFail(ws.path, `origin/${trunk}`, ws.branch, 'resolve them here, commit the merge, then run able ws merge again')
39
45
 
40
- if (!runChecks(config, lines(ws.path, 'diff', '--name-only', `origin/${trunk}...HEAD`), ws)) fail('a check failed; fix it here, commit, and run it again; nothing was pushed')
41
- // A check that formats files leaves them changed: they go in before landing.
42
- if (dirtyCount(ws.path) && !commitAll('Format before landing')) fail('could not commit what the checks changed')
46
+ const checked = runChecks(config, lines(ws.path, 'diff', '--name-only', `origin/${trunk}...HEAD`), ws) && runMergeChecks(config, ws)
47
+ if (!checked) fail('a check failed; fix it here, commit, and run it again; nothing was pushed')
48
+ // A check that formats files leaves them changed: they go in before the merge.
49
+ if (dirtyCount(ws.path) && !commitAll('Format before merging')) fail('could not commit what the checks changed')
43
50
 
44
51
  if (!gitLoud(ws.path, 'push', '--quiet', '-u', 'origin', ws.branch)) fail(`push of ${ws.branch} failed`)
45
52
 
46
- // The branch already holds the trunk, so the landing merge cannot conflict.
47
- if (!gitLoud(ws.path, 'checkout', '--quiet', '--detach', `origin/${trunk}`) || !gitLoud(ws.path, 'merge', '--quiet', '--no-ff', '-m', `Land ${ws.branch}`, ws.branch))
48
- fail('could not build the landing commit')
49
- const landed = git(ws.path, 'rev-parse', 'HEAD')
53
+ // The branch already holds the trunk, so this merge cannot conflict.
54
+ if (!gitLoud(ws.path, 'checkout', '--quiet', '--detach', `origin/${trunk}`) || !gitLoud(ws.path, 'merge', '--quiet', '--no-ff', '-m', `Merge ${ws.branch}`, ws.branch))
55
+ fail('could not build the merge commit')
56
+ const merged = git(ws.path, 'rev-parse', 'HEAD')
50
57
  const pushed = gitLoud(ws.path, 'push', '--quiet', 'origin', `HEAD:${trunk}`)
51
58
  gitLoud(ws.path, 'checkout', '--quiet', ws.branch)
52
59
  if (!pushed) fail(`${trunk} moved meanwhile; run it again to merge it in`)
53
60
  console.log(`\n ${green('✓')} ${bold(ws.branch)} is on ${trunk}`)
54
61
 
55
- // `--ff-only` either moves the main checkout to the landing or refuses without touching it.
62
+ // `--ff-only` either moves the main checkout to the merge or refuses without touching it.
56
63
  const onTrunk = git(ws.main, 'rev-parse', '--abbrev-ref', 'HEAD') === trunk
57
- const synced = onTrunk && gitQuiet(ws.main, 'merge', '--quiet', '--ff-only', landed)
64
+ const synced = onTrunk && gitQuiet(ws.main, 'merge', '--quiet', '--ff-only', merged)
58
65
  console.log(
59
66
  synced
60
67
  ? ` ${green('✓')} main checkout fast-forwarded`
@@ -26,7 +26,7 @@ for (const source of sources.filter(Boolean)) {
26
26
  continue
27
27
  }
28
28
  const unpushed = source === trunk && remote ? count(ws.path, `${remote}..${trunk}`) : 0
29
- console.log(` ${bold(source)}: ${behind} commit(s)${unpushed ? yellow(`; ${unpushed} not on origin yet, they reach it when this workspace lands`) : ''}`)
29
+ console.log(` ${bold(source)}: ${behind} commit(s)${unpushed ? yellow(`; ${unpushed} not on origin yet, they reach it when this workspace is merged`) : ''}`)
30
30
  mergeOrFail(ws.path, source, ws.branch, 'resolve them here and commit the merge, or abort it with git merge --abort')
31
31
  }
32
32
  console.log(`\n${green('✓')} ${bold(ws.branch)} holds ${trunk}\n`)
package/sync.ts CHANGED
@@ -3,8 +3,8 @@
3
3
  //
4
4
  // able sync [--dry-run]
5
5
  //
6
- // From the host's main checkout, on the trunk (`trunk` in its able.config.ts). For every workspace landed on
7
- // the trunk (a `Land feat/<slug>` merge) it reads the workspace's brief and:
6
+ // From the host's main checkout, on the trunk (`trunk` in its able.config.ts). For every workspace merged into
7
+ // the trunk (a `Merge feat/<slug>` commit, or `Land feat/<slug>` from before decision 100) it reads the workspace's brief and:
8
8
  // files each "Raised for later" bullet as an issue (labels `follow-up`, `ws:<slug>`), found again
9
9
  // by the marker `<!-- able:<slug>:<title> -->` in its body, so none is filed twice
10
10
  // closes the issues listed under "Closed follow-ups" (`- #12 …`), as completed
@@ -35,7 +35,7 @@ const { trunk, journal } = await loadConfig(root)
35
35
  const git = (...a: string[]) => run(['git', ...a], root)
36
36
  const gh = (...a: string[]) => run([process.execPath, join(import.meta.dir, 'able.ts'), 'gh', ...a], root)
37
37
 
38
- // A workspace is a linked worktree: its records reach the trunk only when it lands.
38
+ // A workspace is a linked worktree: its records reach the trunk only when it is merged.
39
39
  if (resolve(root, git('rev-parse', '--git-dir')) !== resolve(root, git('rev-parse', '--git-common-dir'))) {
40
40
  console.log('able sync: inside a workspace; it runs in the main checkout. Nothing done.')
41
41
  process.exit(0)
@@ -43,7 +43,7 @@ if (resolve(root, git('rev-parse', '--git-dir')) !== resolve(root, git('rev-pars
43
43
 
44
44
  Bun.spawnSync(['git', 'fetch', '--quiet', 'origin', trunk], { cwd: root, stdout: 'ignore', stderr: 'ignore' })
45
45
  const behind = Number(git('rev-list', '--count', `HEAD..origin/${trunk}`) || '0')
46
- if (behind) fail(`this checkout is ${behind} commit(s) behind origin/${trunk}; pull first, or the records that landed since are missed. Nothing done.`)
46
+ if (behind) fail(`this checkout is ${behind} commit(s) behind origin/${trunk}; pull first, or the records merged since are missed. Nothing done.`)
47
47
 
48
48
  // ── Markdown: `## ` sections and their `### ` subsections ─────────────────────────────────────
49
49
 
@@ -73,14 +73,14 @@ const bullets = (slug: string, block: string): Item[] =>
73
73
  return { slug, title, text, key: `${slug}:${slugify(title)}` }
74
74
  })
75
75
 
76
- // ── Landed workspaces and their briefs ────────────────────────────────────────────────────────
76
+ // ── Merged workspaces and their briefs ────────────────────────────────────────────────────────
77
77
 
78
- type Land = { slug: string; hash: string; at: number; brief?: string }
79
- const lands = new Map<string, Land>()
78
+ type Merged = { slug: string; hash: string; at: number; brief?: string }
79
+ const merges = new Map<string, Merged>()
80
80
  for (const line of git('log', `origin/${trunk}`, '--merges', '--format=%H%x09%ct%x09%s').split('\n').filter(Boolean)) {
81
81
  const [hash = '', at = '0', subject = ''] = line.split('\t')
82
- const slug = subject.match(/^Land feat\/(\S+)$/)?.[1]
83
- if (slug && !lands.has(slug)) lands.set(slug, { slug, hash, at: Number(at) * 1000 })
82
+ const slug = subject.match(/^(?:Merge|Land) feat\/(\S+)$/)?.[1]
83
+ if (slug && !merges.has(slug)) merges.set(slug, { slug, hash, at: Number(at) * 1000 })
84
84
  }
85
85
 
86
86
  // A brief is `<journal>/workspaces/<slug>.md`; one written before that layout stays where it is, beside the journal.
@@ -88,10 +88,10 @@ const briefs = new Map<string, string>()
88
88
  for (const path of new Bun.Glob(`${dirname(journal)}/**/*.md`).scanSync(root)) {
89
89
  const name = path.split('/').at(-1)!.slice(0, -3)
90
90
  if (path === `${journal}/workspaces/${name}.md` || !briefs.has(name)) {
91
- if (lands.has(name) && (await Bun.file(join(root, path)).text()).includes('\n## Ledger\n')) briefs.set(name, path)
91
+ if (merges.has(name) && (await Bun.file(join(root, path)).text()).includes('\n## Ledger\n')) briefs.set(name, path)
92
92
  }
93
93
  }
94
- for (const land of lands.values()) land.brief = briefs.get(land.slug)
94
+ for (const m of merges.values()) m.brief = briefs.get(m.slug)
95
95
 
96
96
  // ── Follow-ups ────────────────────────────────────────────────────────────────────────────────
97
97
 
@@ -115,19 +115,19 @@ const ensureLabel = (name: string, color: string, description: string) => {
115
115
  }
116
116
 
117
117
  const texts = new Map<string, string>()
118
- for (const land of lands.values()) if (land.brief) texts.set(land.slug, await Bun.file(join(root, land.brief)).text())
118
+ for (const m of merges.values()) if (m.brief) texts.set(m.slug, await Bun.file(join(root, m.brief)).text())
119
119
 
120
120
  const filed: Item[] = []
121
121
  const closed: { slug: string; number: number }[] = []
122
- for (const land of lands.values()) {
123
- const ledger = section(texts.get(land.slug) ?? '', 'Ledger')
124
- for (const item of bullets(land.slug, sub(ledger, 'Raised for later'))) {
122
+ for (const m of merges.values()) {
123
+ const ledger = section(texts.get(m.slug) ?? '', 'Ledger')
124
+ for (const item of bullets(m.slug, sub(ledger, 'Raised for later'))) {
125
125
  if (byKey.has(item.key)) continue
126
126
  filed.push(item)
127
127
  if (dry) continue
128
128
  ensureLabel('follow-up', '5319e7', 'Raised for later by an Able workspace')
129
129
  ensureLabel(`ws:${item.slug}`, 'bfd4f2', 'The workspace that raised it')
130
- const link = `https://github.com/${repo}/blob/${trunk}/${land.brief}`
130
+ const link = `https://github.com/${repo}/blob/${trunk}/${m.brief}`
131
131
  const body = `${item.text}\n\nRaised for later in \`${item.slug}\`: ${link}\n\n<!-- able:${item.key} -->\n`
132
132
  const url = gh('issue', 'create', '--title', item.title, '--body', body, '--label', 'follow-up', '--label', `ws:${item.slug}`)
133
133
  const now = new Date().toISOString()
@@ -138,9 +138,9 @@ for (const land of lands.values()) {
138
138
  for (const n of [...sub(ledger, 'Closed follow-ups').matchAll(/^- .*?#(\d+)/gm)].map((m) => Number(m[1]))) {
139
139
  const issue = issues.find((i) => i.number === n)
140
140
  if (issue?.state !== 'OPEN') continue
141
- closed.push({ slug: land.slug, number: n })
141
+ closed.push({ slug: m.slug, number: n })
142
142
  if (dry) continue
143
- gh('issue', 'close', String(n), '--reason', 'completed', '--comment', `Closed by \`${land.slug}\`, which took it on.`)
143
+ gh('issue', 'close', String(n), '--reason', 'completed', '--comment', `Closed by \`${m.slug}\`, which took it on.`)
144
144
  issue.state = 'CLOSED'
145
145
  issue.closedAt = new Date().toISOString()
146
146
  }
@@ -207,8 +207,8 @@ const record = (start: number) => {
207
207
  const end = addDays(start, 7)
208
208
  const name = weekName(start)
209
209
  const inWeek = (t: number) => t >= start && t < end
210
- const landed = [...lands.values()].filter((l) => inWeek(l.at)).sort((a, b) => a.at - b.at)
211
- const rows = landed.map((l) => {
210
+ const merged = [...merges.values()].filter((l) => inWeek(l.at)).sort((a, b) => a.at - b.at)
211
+ const rows = merged.map((l) => {
212
212
  const changed = git('diff', '--name-only', `${l.hash}^1`, l.hash).split('\n').filter(Boolean)
213
213
  const commits = git('rev-list', '--count', `${l.hash}^1..${l.hash}^2`)
214
214
  const packages = [...new Set(changed.map(packageOf))].sort().join(', ')
@@ -228,9 +228,9 @@ status: stable
228
228
 
229
229
  Monday ${date(start)} to Sunday ${date(addDays(start, 6))}. Written by \`able sync\` from git, the briefs and the follow-up issues.
230
230
 
231
- ## Landed
231
+ ## Merged
232
232
 
233
- ${rows.length ? `| Workspace | Landed | Commits | Packages |\n|---|---|---|---|\n${rows.join('\n')}` : 'Nothing landed.'}
233
+ ${rows.length ? `| Workspace | Merged | Commits | Packages |\n|---|---|---|---|\n${rows.join('\n')}` : 'Nothing merged.'}
234
234
 
235
235
  ## Follow-ups raised
236
236