@able-autonomy/able 0.0.7 → 0.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@able-autonomy/able",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
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",
@@ -1,18 +1,23 @@
1
- // able ws new <slug> [--no-fetch]: a worktree on `feat/<slug>` cut from origin's trunk, in `workspaces.dir`, then
1
+ // able ws new <slug> [--brief] [--no-fetch]: a worktree on `feat/<slug>` cut from origin's trunk, in `workspaces.dir`, then
2
2
  // what a worktree can't inherit: the host's `copy` files and its `onCreate` commands, with this workspace's facts in
3
3
  // `ABLE_WS_*`. Services are not started: `able ws start` does that. Every check runs before anything is created.
4
+ //
5
+ // `--brief` first publishes the workspace's brief, `<journal>/workspaces/<slug>.md`, from the main checkout on the trunk:
6
+ // it commits that file alone after its checks, when it has changes, and pushes the trunk, so the cut carries it. It
7
+ // refuses while the trunk has other unpushed commits, which would leave with it.
4
8
 
5
9
  import { copyFileSync, existsSync, mkdirSync } from 'node:fs'
6
10
  import { dirname, join, relative, resolve } from 'node:path'
7
11
  import { loadConfig } from '../../config.ts'
8
- import { fetchTrunk, git, mainRoot } from '../git.ts'
12
+ import { runChecks } from '../checks.ts'
13
+ import { count, failOnMerge, fetchTrunk, git, gitLoud, mainRoot } from '../git.ts'
9
14
  import { runCommand } from '../run.ts'
10
15
  import { bold, dim, fail, green, yellow } from '../ui.ts'
11
16
  import { branchOf, readState, workspaces, writeState } from './state.ts'
12
17
 
13
18
  const args = process.argv.slice(4)
14
19
  const slug = args.find((a) => !a.startsWith('-'))
15
- if (!slug) fail('usage: able ws new <slug> [--no-fetch]')
20
+ if (!slug) fail('usage: able ws new <slug> [--brief] [--no-fetch]')
16
21
  if (!/^[a-z0-9][a-z0-9-]*$/.test(slug)) fail(`invalid name '${slug}': lowercase letters, digits and dashes only`)
17
22
 
18
23
  const main = mainRoot()
@@ -32,6 +37,23 @@ const { ports } = ws
32
37
  const portOffset = ports ? (Array.from({ length: ports.max }, (_, i) => (i + 1) * ports.step).find((o) => !taken.has(o)) ?? fail('no free port offset; remove a workspace first')) : 0
33
38
 
34
39
  if (!args.includes('--no-fetch')) fetchTrunk(main, config.trunk)
40
+
41
+ if (args.includes('--brief')) {
42
+ const { trunk, journal } = config
43
+ const file = `${journal}/workspaces/${slug}.md`
44
+ if (!existsSync(join(main, file))) fail(`no brief at ${file}; write it first`)
45
+ if (git(main, 'rev-parse', '--abbrev-ref', 'HEAD') !== trunk) fail(`the main checkout is not on ${trunk}`)
46
+ failOnMerge(main)
47
+ const unpushed = git(main, 'log', '--oneline', `origin/${trunk}..${trunk}`)
48
+ if (unpushed) fail(`${trunk} has unpushed commits that would leave with the brief:\n${unpushed}`)
49
+ if (git(main, 'status', '--porcelain', '--', file)) {
50
+ const at = { slug: 'main', path: main, portOffset: 0, main }
51
+ if (!runChecks(config, [file], at)) fail('a check failed; nothing committed')
52
+ if (!gitLoud(main, 'add', '--', file) || !gitLoud(main, 'commit', '--quiet', '-m', `journal: ${slug} brief`, '--', file)) fail('commit of the brief failed')
53
+ }
54
+ if (count(main, `origin/${trunk}..${trunk}`) && !gitLoud(main, 'push', '--quiet', 'origin', trunk)) fail(`push of ${trunk} failed`)
55
+ }
56
+
35
57
  // Cut from origin's trunk: the main checkout's own branch may lag, and is the operator's to move.
36
58
  const start = git(main, 'rev-parse', '--verify', '--quiet', `origin/${config.trunk}`) ? `origin/${config.trunk}` : config.trunk
37
59